home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15178 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Re: compiling problem under g++
  5. Date: Thu, 04 Apr 96 00:20:30 GMT
  6. Organization: none
  7. Message-ID: <828577230snz@genesis.demon.co.uk>
  8. References: <3161A2D3.7D84@psu.edu> <4jtsdm$hba@nadine.teleport.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4jtsdm$hba@nadine.teleport.com> hksys@teleport.com "GHouck" writes:
  15.  
  16. >"Jason A. Soloff" <jas251@psu.edu> wrote:
  17. >>Minor problem here... I have been coding in C++ for years on the Dos/win 
  18. >>platforms, and am running into (what has to be) a simple, but annoying 
  19. >>problem...
  20. >>
  21. >>#include <math.h>
  22. >>int main(void)
  23. >>{
  24. >>  printf("%f\n",sqrt(25));
  25. >>  return 0;
  26. >>}
  27. >>
  28. >>OK... thats it... nice and simple huh?  Nope.
  29. >>Won't compile on two unix systems I am trying to work with...
  30. >>SunOS 4.1.3_U1, with g++ 2.4  It can't seem to find the
  31. >>sqrt code from the library?  Am I missing something?  is the
  32. >>library called something else under UNIX?
  33.  
  34. See section 14.3 od the FAQ.
  35.  
  36. >Jason,
  37. >
  38. >If the '25' is truly an integer, perhaps that is the
  39. >problem, since there probably is no function available
  40. >to take the square root of an integer, but rather
  41. >a double.  Unless, of course, it casts it, then ...
  42.  
  43. A C compiler can convert implicitly between integer anf floating point
  44. types. Since math.h is included an ANSI compiler must perform that conversion
  45. in the code example. With a pre-ANSI compiler without prototyped standard
  46. library declarations in header files the compiler wouldn't perform the
  47. appropriate conversion. On the other hand it is not likely to know enough
  48. to reject the program at compile time.
  49.  
  50. -- 
  51. -----------------------------------------
  52. Lawrence Kirby | fred@genesis.demon.co.uk
  53. Wilts, England | 70734.126@compuserve.com
  54. -----------------------------------------
  55.